# Django settings for minutes project.
import os

DEBUG = True
TEMPLATE_DEBUG = DEBUG

ADMINS = (
    # ('Your Name', 'your_email@domain.com'),
)

MANAGERS = ADMINS

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
        'NAME': '8minutes',                      # Or path to database file if using sqlite3.
        'USER': 'igor',                      # Not used with sqlite3.
        'PASSWORD': '',                  # Not used with sqlite3.
        'HOST': '',                      # Set to empty string for localhost. Not used with sqlite3.
        'PORT': '',                      # Set to empty string for default. Not used with sqlite3.
    }
}

# Local time zone for this installation. Choices can be found here:
# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
# although not all choices may be available on all operating systems.
# On Unix systems, a value of None will cause Django to use the same
# timezone as the operating system.
# If running in a Windows environment this must be set to the same as your
# system time zone.
TIME_ZONE = 'America/Chicago'

# Language code for this installation. All choices can be found here:
# http://www.i18nguy.com/unicode/language-identifiers.html
LANGUAGE_CODE = 'en-us'

SITE_ID = 1

# If you set this to False, Django will make some optimizations so as not
# to load the internationalization machinery.
USE_I18N = True

# If you set this to False, Django will not format dates, numbers and
# calendars according to the current locale
USE_L10N = True

# Absolute filesystem path to the directory that will hold user-uploaded files.
# Example: "/home/media/media.lawrence.com/"
MEDIA_ROOT = (os.path.normpath(os.path.join(os.path.dirname(__file__), '..', 'uploads')).
        replace('\\', '/'))

# URL that handles the media served from MEDIA_ROOT. Make sure to use a
# trailing slash if there is a path component (optional in other cases).
# Examples: "http://media.lawrence.com", "http://example.com/media/"
MEDIA_URL = '/uploads/'

# URL prefix for admin media -- CSS, JavaScript and images. Make sure to use a
# trailing slash.
# Examples: "http://foo.com/media/", "/media/".
ADMIN_MEDIA_PREFIX = '/media/'

# Make this unique, and don't share it with anybody.
SECRET_KEY = '^^8vjjpwr+ou_ki6w4_37wc)vdm+6(#8bmgsjyr$&fey-@_%$n'

# List of callables that know how to import templates from various sources.
TEMPLATE_LOADERS = (
    'django.template.loaders.filesystem.Loader',
    'django.template.loaders.app_directories.Loader',
#     'django.template.loaders.eggs.Loader',
)

MIDDLEWARE_CLASSES = (
    'django.middleware.common.CommonMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'mitems.middleware.GraphMiddleware',
    'mitems.middleware.AjaxMessaging',
)

ROOT_URLCONF = 'minutes.urls'

TEMPLATE_DIRS = (
    # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
    # Always use forward slashes, even on Windows.
    # Don't forget to use absolute paths, not relative paths.
    os.path.normpath(os.path.join(os.path.dirname(__file__), 'templates')).replace('\\', '/'),
)

TEMPLATE_CONTEXT_PROCESSORS = (
    'django.core.context_processors.auth',
    'django.core.context_processors.debug',
    'django.core.context_processors.i18n',
    'django.core.context_processors.media',
    'django.core.context_processors.static',
    'django.core.context_processors.request',
    'django.contrib.messages.context_processors.messages',
    'mitems.context_processors.analytics',
)

INSTALLED_APPS = (
    'fix_email_length',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
#    'minutes.mitems',
    'mitems',
    'django.contrib.humanize',
    # Uncomment the next line to enable the admin:
    'django.contrib.admin',
    'social_auth',
    'south',
    'django_autoslug',
    'shorturls',
    'persistent_messages',
    'mailer'
    # Uncomment the next line to enable admin documentation:
    # 'django.contrib.admindocs',
)

AUTHENTICATION_BACKENDS = (
    'social_auth.backends.facebook.FacebookBackend',
    'social_auth.backends.twitter.TwitterBackend',
    'social_auth.backends.google.GoogleOAuthBackend',
    'django.contrib.auth.backends.ModelBackend',
)

MESSAGE_STORAGE = 'persistent_messages.storage.PersistentMessageStorage'

DJANGO_LOG_FILE = (os.path.normpath(os.path.join(os.path.dirname(__file__),
                                               '..', 'log', 'django.log')).replace('\\', '/'))
LOGGING = {
    'version': 1,
    'disable_existing_loggers': True,
    'formatters': {
        'verbose': {
            'format': '%(levelname)s %(asctime)s %(module)s %(process)d %(thread)d %(message)s'
        },
        'simple': {
            'format': '%(levelname)s %(message)s'
        },
    },
    'handlers': {
        'null': {
            'level':'DEBUG',
            'class':'django.utils.log.NullHandler',
        },
        'console':{
            'level':'DEBUG',
            'class':'logging.StreamHandler',
            'formatter': 'simple'
        },
        'mail_admins': {
            'level': 'ERROR',
            'class': 'django.utils.log.AdminEmailHandler',
        },
        'log_file': {
             'level': 'DEBUG',
             'class': 'logging.handlers.RotatingFileHandler',
             'filename': DJANGO_LOG_FILE,
             'formatter': 'verbose',
             'backupCount': 10,
             'maxBytes': 10*2**20,
        },

    },
    'loggers': {
        'django': {
            'handlers':['null'],
            'propagate': True,
            'level':'INFO',
        },
        'minutes': {
            'handlers': ['console', 'log_file'],
            'level': 'INFO',
        },
          'django.request': {
            'handlers': ['mail_admins'],
            'level': 'ERROR',
            'propagate': False,
        },
    }
}

FIXTURE_DIRS = (
   os.path.normpath(os.path.join(os.path.dirname(__file__), 'fixtures')).replace('\\', '/'),
)

STATIC_ROOT_FILES = os.path.normpath(os.path.join(os.path.dirname(__file__), 'static')).replace('\\', '/')
STATICFILES_DIRS = (
    STATIC_ROOT_FILES,
)
STATIC_URL = "/static/"
SITE_ID = 1

LOGIN_URL = '/login/facebook/'
LOGIN_REDIRECT_URL = '/welcome/'
LOGIN_ERROR_URL    = '/signin-error/'


FACEBOOK_EXTENDED_PERMISSIONS = ['publish_stream', 'offline_access',
                                 'email', 'user_birthday', 'user_location',
                                 'user_interests']
SOCIAL_AUTH_ERROR_KEY = 'social_errors'
SOCIAL_AUTH_COMPLETE_URL_NAME  = 'complete'
SOCIAL_AUTH_ASSOCIATE_URL_NAME = 'associate_complete'
SOCIAL_AUTH_DEFAULT_USERNAME = 'new_social_auth_user'
SOCIAL_AUTH_EXTRA_DATA = True
SOCIAL_AUTH_EXPIRATION = 'expires'
SOCIAL_AUTH_SESSION_EXPIRATION = False

AUTH_PROFILE_MODULE = "mitems.UserProfile"
SOCIAL_AUTH_USER_MODEL = "mitems.UserProfile"
SOCIAL_AUTH_CHANGE_SIGNAL_ONLY = True
SOCIAL_AUTH_ASSOCIATE_BY_MAIL = False

SHORTEN_MODELS = { 'P': 'mitems.item' }
SHORT_BASE_URL = 'http://8-m.in/'

TWITTER_MAX_LENGTH = 140

ITEMS_PER_PAGE = 10
DEV_STORIES_PER_PAGE = 6
DEV_STORIES_TIME_FRAME = 8*60*60
RELATED_STORIES_PER_PAGE = 5
FOLLOWS_PER_PAGE = 20
CYCLE_SECONDS = 8*60
MIN_OPACITY = 0.4
USERNAME_LENGTH = 20
AIRTIME_PER_CYCLE = 16
FACEBOOK_PHOTO_URL = "https://graph.facebook.com/%s/picture?type=large"

IMAGE_LIMIT_SIZE = 5*1024*1024
IMAGE_PROFILE_LIMIT_SIZE = 5*1024*1024
IMAGE_SIZE = (256, 256)
IMAGE_SIZE_STORY = (640, 480)

MAIL_MAX_ATTACH = 5*1024*1024
MAIL_AIRTIME_COUNT = 32
MAIL_LOG_SIZE = 5*1024*1024
MAIL_LOG_COUNT = 20
MAIL_LOG_FILE = (os.path.normpath(os.path.join(os.path.dirname(__file__),
                                               '..', 'log', 'mail.log')).replace('\\', '/'))
MAIL_LOG_LOGGER = 'mail'

FEED_LOG_SIZE = 5*1024*1024
FEED_LOG_COUNT = 20
FEED_LOG_FILE = (os.path.normpath(os.path.join(os.path.dirname(__file__),
                                               '..', 'log', 'feed.log')).replace('\\', '/'))
FEED_LOG_LOGGER = 'feed'

TWITTER_LOG_SIZE = 5*1024*1024
TWITTER_LOG_COUNT = 20
TWITTER_LOG_FILE = (os.path.normpath(os.path.join(os.path.dirname(__file__),
                                               '..', 'log', 'twitter.log')).replace('\\', '/'))
TWITTER_LOG_LOGGER = 'twitter'

TWITTER_PUBLIC_USER_TOKEN_SECRET = 'C0XAu8hoIRYLJQFVU63XbcYxXM8J5tgb36SAhoDGp8'
TWITTER_PUBLIC_USER_TOKEN = '312598426-ew4zN7xN2wN8H0ghbyNCLhbeHDoPdUstWpJdgsdT'
TWITTER_MINUTES_TO_LIVE = 8

MAIL_DIR = (os.path.normpath(os.path.join(os.path.dirname(__file__),
                                          '..', 'mail')).replace('\\', '/'))
MOBILE_DOMAIN = 'mobile.8minut.es'

IMAGE_FORMAT = "JPEG"
IMAGE_UPLOADING_ERROR = {'error':
                             'image processing failed.'
                             'Make sure its gif or jpg or png and up to 3MB.'
                        }
MIN_AIRTIME_COUNT = 8
DEFAULT_AIRTIME_COUNT = 80
MAX_RESPONSES = 5
FACEBOOK_MESSAGE = "Click to see how this story is ranked on 8minutes and to keep it live!"
TWITTER_MESSAGE = "%s - Click to see how this story is ranked on @8minutes %s"
CHAPTERS = ('submit','8live', 'popular', 'justin', 'slumpin')
GEOIP_PATH = (os.path.normpath(os.path.join(os.path.dirname(__file__), '..')).
        replace('\\', '/'))

COOKIE_MAX_AGE = 3600*24*30
MESSAGE_CLOSE_TIMEOUT  = 10000
MESSAGE_EXPIRE_TIMEOUT = 10

MAX_UI = 1
MAX_ISS = 5

MIN_REPUTATION = 0.9

EMAIL_HOST = 'localhost'
EMAIL_PORT = 25
EMAIL_HOST_USER = ''
EMAIL_HOST_PASSWORD = ''
EMAIL_USE_TLS = False
EMAIL_FROM = '8minutes <noreply@mobile.8minut.es>'
SERVER_EMAIL = '8minutes <noreply@mobile.8minut.es>'

BROADCASTERS_TIME_FRAME = 24*60*60
BROADCASTERS_DEFAULT_PERCENT = 10
BROADCASTERS_AMOUNT = 5
BROADCASTERS_HISTORY = 8

GOOGLE_CONSUMER_KEY          = ''
GOOGLE_CONSUMER_SECRET       = ''
GOOGLE_OAUTH_EXTRA_SCOPE = ['https://www.google.com/m8/feeds/']
GOOGLE_DISPLAY_NAME = '8minutes'
GOOGLE_INVITE_MESSAGE = "I\'d like to share my news items with you on 8minutes."


MAX_USERNAME_LENGTH = 100
MAX_EMAIL_LENGTH = 300

EMAIL_BACKEND = "mailer.backend.DbBackend"
CACHES = {
    'default': {
        'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',
        'LOCATION': '127.0.0.1:11211',
        'TIMEOUT': 60,
        'OPTIONS': {
            'MAX_ENTRIES': 1000
        }
    }
}

try:
    from local_settings import *
except ImportError:
    print 'NO LOCAL SETTINGS'
    pass
